package org.bingdianleil.config;

import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.pool.DruidDataSource;

@Configuration
public class DataSourceConfig {
	
	@Value("${datasource.driver-class-name}")
	private String DriverClassName;
	
	@Value("${datasource.url}")
	private String Url;
	
	@Value("${datasource.username}")	
	private String UserName;
	
	@Value("${datasource.password}")	
	private String PassWord;
	
	
	@Bean
	public DruidDataSource druidDataSource() throws SQLException { 
		//Druid 数据源配置  
		DruidDataSource	dataSource = new DruidDataSource(); 
		dataSource.setDriverClassName(DriverClassName);
		dataSource.setUrl(Url); 
		dataSource.setUsername(UserName);
		dataSource.setPassword(PassWord); //初始连接数(默认值0) 
		dataSource.setInitialSize(8); //最小连接数(默认值0) 
		dataSource.setMinIdle(8); //最大连接数(默认值8,注意"maxIdle"这个属性已经弃用) 
		dataSource.setMaxActive(32);
		dataSource.setFilters("stat");
		dataSource.setPoolPreparedStatements(true);
		return dataSource; 
		}
	 
}
